package com.wushe.firstexample;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * @description:
 * @author: WuShe
 * @date: 2019/11/28 13:45
 * @version: 1.0.0
 * @modified By:
 */
public class TestServer {
    public static void main(String[] args) throws InterruptedException {
        //定义两个异步事件循环组
        EventLoopGroup boss = new NioEventLoopGroup();//接收连接
        EventLoopGroup work = new NioEventLoopGroup();//处理连接
        try {
            ServerBootstrap bootstrap = new ServerBootstrap();//启动配置类
            bootstrap.group(boss, work).channel(NioServerSocketChannel.class)
                    .childHandler(new TestServerInitializer());
            ChannelFuture future = bootstrap.bind(8899).sync();
            future.channel().closeFuture().sync();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }finally {
            boss.shutdownGracefully();//优雅的关闭
            work.shutdownGracefully();
        }
    }
}
